home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-09-21 | 654 b | 34 lines | [TEXT/ttxt] |
- //-------------------------------------------------------------------//
- //
- // 1st cut at sign function
- // Return 1, if element >= 0
- // Return 0, if element == 0
- // Return -1, if element < 0
- //
- // Does not handle complex quantities like MATLAB
- //
-
- sign = function ( a )
- {
- local(i, j, r);
-
- if (class (a) != "num") { error ("sign() requires NUMERIC arg"); }
- if (type (a) == "complex")
- {
- return a ./ abs(a);
- }
-
- r = zeros( size (a) );
- for(i in 1:size (a)[1])
- {
- for(j in 1:size (a)[2])
- {
- if(a[i;j] > 0) { r[i;j] = 1; }
- if(a[i;j] == 0) { r[i;j] = 0; }
- if(a[i;j] < 0) { r[i;j] =-1; }
- }
- }
-
- return r;
- };
-